package com.zky.gulimall.order.web;

import com.alipay.api.AlipayApiException;
import com.zky.gulimall.order.config.AlipayTemplate;
import com.zky.gulimall.order.service.OrderService;
import com.zky.gulimall.order.vo.PayVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @Description 支付宝支付controller
 * @Author 张开源
 * @Date 2022/12/23 0:15
 * @Version 1.0
 **/
@Controller
@Slf4j
public class PayWebController {

    @Autowired
    private AlipayTemplate alipayTemplate;
    @Autowired
    private OrderService orderService;

    @ResponseBody
    @GetMapping(value = "/payOrder", produces = "text/html")
    public String payOrder(@RequestParam("orderSn") String orderSn) throws AlipayApiException {
        PayVo payVo = orderService.getPayOrder(orderSn);
        //支付宝返回的是一个页面，用来跳转支付宝后需支付的页面
        String pay = alipayTemplate.pay(payVo);
        log.warn("pay:{}", pay);
        return pay;
    }
}
